package com.mlh.controller;


import com.mlh.annotation.SystemLog;
import com.mlh.service.ArticleService;
import com.mlh.util.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/article")
@Api(tags = "文章",description = "文章相关接口")
public class ArticleController {
	@Autowired
	private ArticleService articleService;

	//实现前十热门文章查询
	@SystemLog(BusinessName = "获取前十热门文章")
	@GetMapping("/hotArticleList")
	public ResponseResult hotArticle(){
		ResponseResult result=articleService.hotArticleList();
		return result;
	}

	//根据种类id返回文章 并分页
	@GetMapping("/articleList")
	@ApiOperation(value = "同种类文章列表",notes = "获取一页同种类文章")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "pageNum",value = "页号"),
			@ApiImplicitParam(name = "pageSize",value = "每页大小"),
			@ApiImplicitParam(name = "categoryId",value = "种类id")
	})
	public ResponseResult articleList(Integer pageNum,Integer pageSize,Long categoryId){
		return articleService.articleList( pageNum, pageSize, categoryId);
	}

	//获取文章的详细内容
	@GetMapping("/{id}")
	public ResponseResult getArticleDetail(@PathVariable Long id){
		return articleService.getArticleDetail(id);
	}

	//增加文章的阅读量
	@PutMapping("/updateViewCount/{id}")
	public ResponseResult updateViewCount(@PathVariable("id") Long id){
		return articleService.updateViewCount(id);
	}
}
